#region Summary

// 
// Owner : JackieHan 
// 
// Solution : LearnSolution 
// 
// Project : JackieHan.NHibernate3.Test
// 
// File : TestMapMapping.cs
// 
// CopyRight : Copyright © 2010-2011 Skomart Corporation, All Rights Reserved 
// 
// Summary : Summary
// 
// History : 
//			2010-09-19 13:23:33	    Create 
// 

#endregion

#region Using

using System;
using System.Collections.Generic;
using JackieHan.NHibernate3.Domain;
using JackieHan.NHibernate3.Repository;
using NUnit.Framework;

#endregion

namespace JackieHan.NHibernate3.Test
{
    /// <summary> 
    /// Summary
    /// </summary>
    [TestFixture]
    public class TestMapMapping
    {
        [Test]
        public void TestElementMap()
        {
            DictionaryOfElements item = new DictionaryOfElements
                                            {
                                                CreateDate = DateTime.Now,
                                                Creator = "admin",
                                                LastUpdateDate = DateTime.Now,
                                                Updator = "admin",
                                                Version = 1,
                                            };
            item.Elements = new Dictionary<string, DateTime>
                                {
                                    {"aa", DateTime.Now},
                                    {"bb", DateTime.Now},
                                    {"cc", DateTime.Now},
                                    {"dd", DateTime.Now}
                                };

            DictionaryOfElementsRepository db = new DictionaryOfElementsRepository();
            db.Save(item);
        }

        [Test]
        public void TestComponentMap()
        {
            DictionaryOfComponents item = new DictionaryOfComponents
                                              {
                                                  CreateDate = DateTime.Now,
                                                  Creator = "admin",
                                                  Updator = "admin",
                                                  LastUpdateDate = DateTime.Now,
                                                  Version = 1,
                                                  Components = new Dictionary<string, ComponentDictionary>
                                                                   {
                                                                       {
                                                                           "aaa",
                                                                           new ComponentDictionary
                                                                               {IntProperty = 1, StringProperty = "aaa"}
                                                                           },
                                                                       {
                                                                           "bbb",
                                                                           new ComponentDictionary
                                                                               {IntProperty = 1, StringProperty = "bbb"}
                                                                           },
                                                                       {
                                                                           "ccc",
                                                                           new ComponentDictionary
                                                                               {IntProperty = 1, StringProperty = "ccc"}
                                                                           },
                                                                       {
                                                                           "ddd",
                                                                           new ComponentDictionary
                                                                               {IntProperty = 1, StringProperty = "ddd"}
                                                                           }
                                                                   }
                                              };
            DictionaryOfComponentsRepository db = new DictionaryOfComponentsRepository();
            db.Save(item);
        }

        [Test]
        public void TestOneToManyMap()
        {
            DictionaryOfOneToMany item = new DictionaryOfOneToMany
                                             {
                                                 CreateDate = DateTime.Now,
                                                 Creator = "admin",
                                                 Updator = "admiN",
                                                 LastUpdateDate = DateTime.Now,
                                                 Version = 1,
                                                 OneToMany = new Dictionary<long, OneToManyDictionary>
                                                                 {
                                                                     {1, new OneToManyDictionary()},
                                                                     {2, new OneToManyDictionary()},
                                                                     {3, new OneToManyDictionary()},
                                                                     {4, new OneToManyDictionary()},
                                                                 }
                                             };
            DictionaryOfOneToManyRepository db = new DictionaryOfOneToManyRepository();
            db.Save(item);
        }

        [Test]
        public void TestManyToManyMap()
        {
            DictionaryOfManyToMany item = new DictionaryOfManyToMany
                                              {
                                                  CreateDate = DateTime.Now,
                                                  Creator = "admin",
                                                  Updator = "admin",
                                                  LastUpdateDate = DateTime.Now,
                                                  Version = 1
                                              };
            DictionaryOfManyToMany item2 = new DictionaryOfManyToMany
                                               {
                                                   CreateDate = DateTime.Now,
                                                   Creator = "admin",
                                                   Updator = "admin",
                                                   LastUpdateDate = DateTime.Now,
                                                   Version = 1
                                               };
            ManyToManyDictionary child1 = new ManyToManyDictionary
                                              {
                                                  ManyToMany = new Dictionary<long, DictionaryOfManyToMany>
                                                                   {
                                                                       {1, item},
                                                                       {2, item2}
                                                                   }
                                              };
            ManyToManyDictionary child2 = new ManyToManyDictionary
                                              {
                                                  ManyToMany = new Dictionary<long, DictionaryOfManyToMany>
                                                                   {
                                                                       {1, item},
                                                                       {2, item2}
                                                                   }
                                              };
            item.ManyToMany = new Dictionary<long, ManyToManyDictionary>
                                  {
                                      {1, child1},
                                      {2, child2}
                                  };
            item2.ManyToMany = new Dictionary<long, ManyToManyDictionary>
                                  {
                                      {1, child1},
                                      {2, child2}
                                  };

            DictionaryOfManyToManyRepository db = new DictionaryOfManyToManyRepository();
            db.Save(new List<DictionaryOfManyToMany> { item, item2 });
        }

        [Test]
        public void TestKeyManyToManyMap()
        {
            DictionaryKeyManyToMany item = new DictionaryKeyManyToMany
                                             {
                                                 CreateDate = DateTime.Now,
                                                 Creator = "admin",
                                                 LastUpdateDate = DateTime.Now,
                                                 Updator = "admin",
                                                 Version = 1
                                             };
            DictionaryKeyManyToMany item2 = new DictionaryKeyManyToMany
                                                {
                                                    CreateDate = DateTime.Now,
                                                    Creator = "admin",
                                                    LastUpdateDate = DateTime.Now,
                                                    Updator = "admin",
                                                    Version = 1
                                                };
            ManyToManyDictionaryKey child = new ManyToManyDictionaryKey();
                                                //{
                                                //    KeyManyToMany = new Dictionary<DictionaryKeyManyToMany, string>
                                                //                        {
                                                //                            {item, "aaa"},
                                                //                            {item2, "bbb"}
                                                //                        }
                                                //};
            ManyToManyDictionaryKey child2 = new ManyToManyDictionaryKey();
                                                 //{
                                                 //    KeyManyToMany = new Dictionary<DictionaryKeyManyToMany, string>
                                                 //                        {
                                                 //                            {item, "aaa"},
                                                 //                            {item2, "bbb"}
                                                 //                        }
                                                 //};
            item.KeyManyToMany = new Dictionary<ManyToManyDictionaryKey, string>
                                   {
                                       {child,"aaa"},{child2,"aaa"}
                                   };
            item2.KeyManyToMany = new Dictionary<ManyToManyDictionaryKey, string>
                                   {
                                       {child,"aaa"},{child2,"aaa"}
                                   };
            DictionaryKeyManyToManyRepisitory db = new DictionaryKeyManyToManyRepisitory();
            db.Save(new List<DictionaryKeyManyToMany> { item, item2 });
        }

    }
}